{include file="public/header-static"/}
{include file="public/sidebar"/}
<link rel="stylesheet" href="__STATIC__/vendors/select2/css/select2.min.css" type="text/css">

<div id="main">
    {include file="public/header"/}
    <main class="main-content">
        <div class="container">
            <div class="page-header">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item">
                            <a href="#">首页</a>
                        </li>
                        <li class="breadcrumb-item active" aria-current="page">社群编辑</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-body">
                            <form action='{:url("/community/communityEdit")}' method="post" target="iframe_form"
                                  enctype="multipart/form-data">

                                <div class="form-group row">
                                    <input type="hidden" name="id" value="{$info.id}">
                                    <label for="" class="col-sm-1 col-form-label">企业名称<span
                                            class="color4">*</span></label>
                                    <div class="col-sm-8">
                                        <select name="eid" id="eid" class="form-control">
                                            <option value="">请选择企业</option>
                                            {volist name="list['enterprise']" id="vo"}
                                            <option value="{$vo.id}" {if $info.eid == $vo.id}selected{/if}>{$vo.name}</option>
                                            {/volist}
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="" class="col-sm-1 col-form-label">创建者<span
                                            class="color4">*</span></label>
                                    <div class="col-sm-8">
                                        <input type="text" name="uid" value="{$info.uid}" class="form-control" placeholder="创建者ID">
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="" class="col-sm-1 col-form-label">社群名称<span
                                            class="color4">*</span></label>
                                    <div class="col-sm-8">
                                        <input type="text" name="name" value="{$info.name}" class="form-control" placeholder="社群名称">
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label class="col-sm-1 col-form-label">企业二维码<span class="color4">*</span></label>
                                    <div class="col-sm-4">
                                        <input type="hidden" class="form-control qrcode" name="qrcode" required=""
                                               aria-required="true" value="{$info.qrcode}">
                                        <button type="button" class="btn btn-secondary" id="qrcode">上传二维码</button>
                                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                            预览图：
                                            <div class="layui-upload-list uploader-list" style="overflow: auto;"
                                                 id="uploader-qrcode">

                                                <div class="file-iteme original">
                                                    <div name="qrcode" class="handle" src="{$info.qrcode}">
                                                        <span class="fa fa-times"
                                                              style="border-radius: 0.375rem 0.375rem 0 0;"></span>
                                                    </div>
                                                    <img class="myImages" title='点我查看原图' src="{$info.yqrcode}" onclick="lookimg(this.src)">
                                                </div>

                                            </div>
                                        </blockquote>
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="" class="col-sm-1 col-form-label">是否代管<span class="color4">*</span></label>
                                    <div class="input-group col-sm-8">
                                        <select class="form-control" name="is_escrow" aria-required="true">
                                            <option value="">请选择是否代管</option>
                                            <option value="1" {if $info.is_escrow == 1}selected{/if}>是</option>
                                            <option value="0" {if $info.is_escrow == 0}selected{/if}>否</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label class="col-sm-1 col-form-label">社群简介<span class="color4">*</span></label>
                                    <div class="col-sm-8">
                                        <textarea class="custom_text form-control" placeholder="社群简介"
                                                  name="desc">{$info.desc}</textarea>
                                    </div>
                                </div>

                                <div class="form-group row" style="margin-bottom: 0rem;">
                                    <label for="" class="col-sm-1 col-form-label">社群行业</label>
                                    <div class="input-group col-sm-8" {$info.pid}>
                                        <select class="form-control top_cate" aria-required="true"
                                                style="width:37.5%;line-height:35px">
                                            <option value="">请选择一级分类</option>
                                            {volist name="list.topCate" id="vo"}
                                            <option value="{$vo.id}" {if $info.pid == $vo.id}selected{/if}>{$vo.name}</option>
                                            {/volist}
                                        </select>

                                        <select class="form-control child_cate" name="cid" aria-required="true">
                                            <option value="">请选择二级分类</option>
                                            {volist name="list.childCate" id="vo"}
                                            <option value="{$vo.id}" {if $info.cid == $vo.id}selected{/if}>{$vo.name}</option>
                                            {/volist}
                                        </select>

                                        <span class="otherCate" onclick="otherCate(this)">没有匹配的？点我自行添加吧！</span>

                                        </select>
                                    </div>
                                </div>

                                <div class="form-group row" style="display: none;" id="other_cate">
                                    <label for="" class="col-sm-1 col-form-label"></label>
                                    <div class="col-sm-8">
                                        <input type="text" name="other_cate" class="form-control"
                                               placeholder="自定义填写行业所属分类">
                                    </div>
                                </div>

                                <div class="form-group row myMargin">
                                    <label class="col-sm-1 col-form-label">封面</label>
                                    <div class="col-sm-4">
                                        <input type="hidden" class="form-control logo1" name="logo" required=""
                                               aria-required="true"  value="{$info.logo}">
                                        <button type="button" class="btn btn-secondary" id="logo1">上传封面</button>
                                        <span style="color: #6c757d">&nbsp;（ 尺寸建议：<span
                                                style="color: #13da13">50 * 50</span> ）</span>
                                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                            预览图：
                                            <div class="layui-upload-list uploader-list" style="overflow: auto;"
                                                 id="uploader-logo">

                                                <div class="file-iteme original">
                                                    <div name="logo" class="handle" src="{$info.logo}">
                                                        <span class="fa fa-times"
                                                              style="border-radius: 0.375rem 0.375rem 0 0;"></span>
                                                    </div>
                                                    <img class="myImages" title='点我查看原图' src="{$info.ylogo}" onclick="lookimg(this.src)">
                                                </div>

                                            </div>
                                        </blockquote>
                                    </div>
                                </div>

                                <button type="submit" class="btn btn-secondary">提交</button>

                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </main>

    {include file="public/footer"/}
    <script type="text/javascript" src="__STATIC__/vendors/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="__STATIC__/vendors/select2/js/select2.min.js"></script>

    <script>
        // 各种上传
        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;

            // 封面上传
            upload.render({
                elem: '#logo1'
                , url: '{:url("/upload/uploadImages")}?path=resourceLogo'
                , before: function (obj) {
                    layer.msg('封面上传中...', {
                        icon: 16,
                        shade: 0.05,
                        time: 0
                    });
                }
                , done: function (res) {
                    layer.close(layer.msg());//关闭上传提示窗口
                    // console.log(res)
                    //上传完毕
                    var logo = $('.logo1').val();
                    if (logo != '') {
                        // 删除旧图片
                        var element = $('#uploader-logo').children('.file-iteme');
                        if (!element.is('.original')) {
                            console.log('不是原LOGO数据，删除');
                            delImageOrVideo(logo);
                        }
                        element.remove();
                    }
                    $('.logo1').val(res.data.src);
                    $('#uploader-logo').append(
                        '<div id="" class="file-iteme">' +
                        '<div name="logo" class="handle" src="' + res.data.src + '"><span class="fa fa-times" style="border-radius: 0.375rem 0.375rem 0 0;"></span></div>' +
                        '<img title=\'点我查看原图\' style="width: 5rem;height: 5rem;border-radius: 0.375rem;cursor: pointer" src=' + res.data.src + ' onclick="lookimg(this.src)">' +
                        // '<div class="info">' + res.data.name + '</div>' +
                        '</div>'
                    );
                }
            });

            // 二维码上传
            upload.render({
                elem: '#qrcode'
                , url: '{:url("/upload/uploadImages")}?path=resourceQrCode'
                , before: function (obj) {
                    layer.msg('二维码上传中...', {
                        icon: 16,
                        shade: 0.05,
                        time: 0
                    });
                }
                , done: function (res) {
                    layer.close(layer.msg());//关闭上传提示窗口
                    // console.log(res)
                    //上传完毕
                    var qrcode = $('.qrcode').val();
                    if (qrcode != '') {
                        // 删除旧图片
                        var element = $('#uploader-qrcode').children('.file-iteme');
                        if (!element.is('.original')) {
                            console.log('不是原二维码数据，删除');
                            delImageOrVideo(qrcode);
                        }
                        element.remove();
                    }
                    $('.qrcode').val(res.data.src);
                    $('#uploader-qrcode').append(
                        '<div id="" class="file-iteme">' +
                        '<div name="qrcode" class="handle" src="' + res.data.src + '"><span class="fa fa-times" style="border-radius: 0.375rem 0.375rem 0 0;"></span></div>' +
                        '<img title=\'点我查看原图\' style="width: 5rem;height: 5rem;border-radius: 0.375rem;cursor: pointer" src=' + res.data.src + ' onclick="lookimg(this.src)">' +
                        // '<div class="info">' + res.data.name + '</div>' +
                        '</div>'
                    );
                }
            });
        });

        // 删除图片
        $(document).on("click", ".file-iteme .handle", function (event) {
            var ele = $('input[name="' + $(this).attr('name') + '"]');
            console.log($(this).attr('name'), $(this).attr('src'), ele);
            if (ele.val() != '') {
                ele.val('');
            }
            if (!$(this).parent().is('.original')) {
                console.log('不是原数据，删除');
                delImageOrVideo($(this).attr('src'));
            }
            $(this).parent().remove();
        });
    </script>

</div>